﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Controls;

namespace SHomeWorkshop.LunarSF.StudentInfosManager.ValidationRules
{
    /// <summary>
    /// 身份证号验证类。
    /// </summary>
    public class CIDRule : LValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string strValue = Format(value.ToString());

            if (_IDCard.CheckCidInfo18(strValue) == "" || _IDCard.CheckCidInfo15(strValue) == "")
                return new ValidationResult(true, null); //验证OK
            else
                return new ValidationResult(false, "“身份证号”不合规则。"); //验证失败
        }

        public static string Format(string origin)
        {
            if (string.IsNullOrWhiteSpace(origin)) return "";

            return FullCharsToHalf(origin).ToUpper();//把末尾的罗马数字格式化为大写。
        }
    }
}
